package com.iversonx.bridge.example_1.v4.controller;


import com.iversonx.bridge.example_1.v4.msg.MessageService;
import com.iversonx.bridge.example_1.v4.msg.impl.CommonMessageService;
import com.iversonx.bridge.example_1.v4.msg.impl.SpecialUrgencyMessageService;
import com.iversonx.bridge.example_1.v4.msg.impl.UrgencyMessageService;

import java.util.ArrayList;
import java.util.List;

/**
 *
 **/
public class MessageControllerV4 {
    private final List<MessageService> messageServiceList;
    private final MessageService defaultMessageService;
    public MessageControllerV4() {
        defaultMessageService = new CommonMessageService();
        
        messageServiceList = new ArrayList<>();
        messageServiceList.add(defaultMessageService);
        messageServiceList.add(new UrgencyMessageService());
        messageServiceList.add(new SpecialUrgencyMessageService());
       
    }
    
    
    public void send(String message, String toUser, String messageType, String sendType) {
        MessageService messageService = getMessageService(messageType);
        messageService.send(message, toUser, sendType);
    }
    
    public MessageService getMessageService(String messageType) {
        for(MessageService messageService : messageServiceList) {
            if(messageService.support(messageType)) {
                return messageService;
            }
        }
        return defaultMessageService;
    }
}
